module.exports = function ($scope, $resource, $modal, toaster) {


	//加载补贴类型
	$scope.getData = function() {
		$resource('/api/as/atc/policy/getSubsidyTypeList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
                $scope.typeList = res.data;
            } else {
                $scope.typeList = [];
            }
        });
	}

    init();
    function init() {
		$scope.obj = {};
        $scope.getData();
    };

    //修改发布状态
    $scope.saveType = function(item) {
		var modalInstance = $modal.open({
			template: require('../views/saveSubsidyType.html'),
			controller: 'saveSubsidyType',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function(result) {
			$scope.getData();
		});

    };

    
    //设置补贴标准
	$scope.delete = function(item, index) {
		if(confirm('确认删除此项补贴类型吗?')){
			$resource('/api/as/atc/policy/deleteSubsidyType', {}, {}).save({'id':item.id}, function(res){
				if (res.errcode === 0) {
					toaster.success({title: '', body: '删除成功'});
					$scope.typeList.splice(index, 1);
				} else {
					toaster.error({title: '', body: res.errmsg});
				}
			});
		}
		
    };
    


};